package com.java.test.agent.module.apply;

import com.java.test.agent.module.apply.dto.AgentApplyDTO;
import com.java.test.agent.module.apply.dto.AgentApplyQueryDTO;
import com.java.test.agent.module.apply.vo.AgentApplyVO;
import com.java.test.controller.BaseController;
import com.java.test.dto.PageResultDTO;
import com.java.test.dto.ResponseDTO;
import com.java.test.system.dto.LoginAccountInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 代理申请Controller
 *
 * @author lijie1
 * @date 2020/6/30 0030
 */
@Slf4j
@RestController
@RequestMapping("/agent/agentApply")
public class AgentApplyController extends BaseController {

    private AgentApplyService agentApplyService;
    @Autowired
    public void setAgentApplyService(AgentApplyService agentApplyService) {
        this.agentApplyService = agentApplyService;
    }

    /**
     * 查询
     * @return
     */
    @RequestMapping(value = "/selectToList",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<AgentApplyVO>> selectByList(@RequestBody @Valid AgentApplyQueryDTO queryDTO) {
        log.debug("----------代理申请列表查询----------");
        return agentApplyService.getSelectByList(queryDTO);
    }

    /**
     * 审核通过
     * @return
     */
    @RequestMapping(value = "/pass",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<AgentApplyVO>> passByIds(@RequestBody @Valid AgentApplyDTO DTO, HttpServletRequest request) {
        log.debug("----------代理申请审核通过----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "代理管理-代理审核-代理审核通过");
        return agentApplyService.passByIds(DTO);
    }


    /**
     * 审核拒绝
     * @return
     */
    @RequestMapping(value = "/fail",method = RequestMethod.POST)
    public ResponseDTO<PageResultDTO<AgentApplyVO>> failByIds(@RequestBody @Valid AgentApplyDTO DTO, HttpServletRequest request) {
        log.debug("----------代理申请审核拒绝----------");
        LoginAccountInfo user = (LoginAccountInfo) request.getSession().getAttribute("user");
        systemManageService.insertlogInfo(user.getLoginAccout(), user.getIp(), "代理管理-代理审核-代理审核拒绝");
        return agentApplyService.failByIds(DTO);
    }
}
